package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;
import lombok.RequiredArgsConstructor;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import ${package.Service}.I${entity}Service;
import ${package.Parent}.common.AjaxResult;
import ${package.Parent}.common.LayuiPage;
import ${package.Entity}.${entity};
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequiredArgsConstructor
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
    private  final I${entity}Service i${entity}Service;

    /**
     * 列表
     * @param vo
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list")
    public LayuiPage<${entity}> list(${entity} vo, int page, int limit) {
        Page<${entity}> pager = new Page<>(page,limit);
        IPage<${entity}> iPage= i${entity}Service.queryPageList(pager,vo);
        return new LayuiPage<>(iPage.getTotal(),iPage.getRecords());
   }



    /**********新增方法*************/
    @GetMapping("/add")
    public ModelAndView add() {
        ModelAndView mv = new ModelAndView("xxx/add");
        return mv;
    }
    @PostMapping("/add")
    public AjaxResult add(${entity} vo) {
        if(i${entity}Service.save(vo)){
        return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    /**********修改方法*************/
    @GetMapping("/update")
    public ModelAndView updateview(${entity} vo, ModelMap map) {
        ${entity} bo= i${entity}Service.getById(vo);
        map.put("bo", bo);

        ModelAndView mv = new ModelAndView("xxx/edit");
        return mv;
    }
    @PutMapping("/update")
    public AjaxResult updateview(${entity} vo) {
        if(i${entity}Service.updateById(vo)){
        return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    /**********删除方法*************/
    @DeleteMapping("/delete")
    public AjaxResult delete(${entity} vo) {
        if(i${entity}Service.removeById(vo)){
        return AjaxResult.success();
        }
        return AjaxResult.error();
    }




    /**********下面写其他逻辑方法*************/

}
</#if>
